import React, { Component } from 'react';
import {Button, InputNumber, Form, message, Input} from 'antd';
import {diffProps} from "../../libs/funcs";

class FormCart extends Component {
    constructor(props) {
        super(props);
        this.state = {};
    }

    handleChangeQuantity = (value) => {
        const { form } = this.props;
        const {field} = this.props;
        form.setFieldsValue({
            [`quantity[${field}]`]:value,
        });
    };
    render() {
        const {getFieldDecorator} = this.props.form;
        const {label,field,initialValue,rules,disabled,addonAfter} = this.props;
        const new_props = diffProps(this.props,["form","label","field","initialValue","rules"]);
        return (
            <Form.Item
                label={label ? <span style={{ wordWrap: 'break-word', whiteSpace: 'normal',lineHeight:'1.5' }}>{label}</span> : "输入框"}
                key={field}
                {...new_props}
            >
                {getFieldDecorator(`quantity[${field}]`, {
                    initialValue: initialValue,
                    rules: rules ? rules : [],
                })(
                    <InputNumber
                        {...(disabled ? { disabled: true } : {})}
                        min={1}
                        value={initialValue}
                        onChange={(value) => this.handleChangeQuantity(value)}
                    />
                )}
                <label  style={{marginLeft: '8px'}}>{addonAfter}</label>
            </Form.Item>
        );
    }
}

export default FormCart;